home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / readline-2.0mg.tar.gz / readline-2.0mg.tar / readline-2.0mg / doc / readline.info-2 (.txt) < prev    next >
GNU Info File  |  1994-08-03  |  37KB  |  890 lines

  1. This is Info file readline.info, produced by Makeinfo-1.55 from the
  2. input file rlman.texinfo.
  3.    This document describes the GNU Readline Library, a utility which
  4. aids in the consistency of user interface across discrete programs that
  5. need to provide a command line interface.
  6.    Copyright (C) 1988, 1991 Free Software Foundation, Inc.
  7.    Permission is granted to make and distribute verbatim copies of this
  8. manual provided the copyright notice and this permission notice pare
  9. preserved on all copies.
  10.    Permission is granted to copy and distribute modified versions of
  11. this manual under the conditions for verbatim copying, provided that
  12. the entire resulting derived work is distributed under the terms of a
  13. permission notice identical to this one.
  14.    Permission is granted to copy and distribute translations of this
  15. manual into another language, under the above conditions for modified
  16. versions, except that this permission notice may be stated in a
  17. translation approved by the Foundation.
  18. File: readline.info,  Node: Modifying Text,  Next: Utility Functions,  Prev: Redisplay,  Up: Readline Convenience Functions
  19. Modifying Text
  20. --------------
  21.  - Function: int rl_insert_text (char *text)
  22.      Insert TEXT into the line at the current cursor position.
  23.  - Function: int rl_delete_text (int start, int end)
  24.      Delete the text between START and END in the current line.
  25.  - Function: char * rl_copy_text (int start, int end)
  26.      Return a copy of the text between START and END in the current
  27.      line.
  28.  - Function: int rl_kill_text (int start, int end)
  29.      Copy the text between START and END in the current line to the
  30.      kill ring, appending or prepending to the last kill if the last
  31.      command was a kill command.  The text is deleted.  If START is
  32.      less than END, the text is appended, otherwise prepended.  If the
  33.      last command was not a kill, a new kill ring slot is used.
  34. File: readline.info,  Node: Utility Functions,  Prev: Modifying Text,  Up: Readline Convenience Functions
  35. Utility Functions
  36. -----------------
  37.  - Function: int rl_reset_terminal (char *terminal_name)
  38.      Reinitialize Readline's idea of the terminal settings using
  39.      TERMINAL_NAME as the terminal type (e.g., `vt100').
  40.  - Function: int alphabetic (int c)
  41.      Return 1 if C is an alphabetic character.
  42.  - Function: int numeric (int c)
  43.      Return 1 if C is a numeric character.
  44.  - Function: int ding ()
  45.      Ring the terminal bell, obeying the setting of `bell-style'.
  46.    The following are implemented as macros, defined in `chartypes.h'.
  47.  - Function: int uppercase_p (int c)
  48.      Return 1 if C is an uppercase alphabetic character.
  49.  - Function: int lowercase_p (int c)
  50.      Return 1 if C is a lowercase alphabetic character.
  51.  - Function: int digit_p (int c)
  52.      Return 1 if C is a numeric character.
  53.  - Function: int to_upper (int c)
  54.      If C is a lowercase alphabetic character, return the corresponding
  55.      uppercase character.
  56.  - Function: int to_lower (int c)
  57.      If C is an uppercase alphabetic character, return the corresponding
  58.      lowercase character.
  59.  - Function: int digit_value (int c)
  60.      If C is a number, return the value it represents.
  61. An Example
  62. ----------
  63.    Here is a function which changes lowercase characters to their
  64. uppercase equivalents, and uppercase characters to lowercase.  If this
  65. function was bound to `M-c', then typing `M-c' would change the case of
  66. the character under point.  Typing `M-1 0 M-c' would change the case of
  67. the following 10 characters, leaving the cursor on the last character
  68. changed.
  69.      /* Invert the case of the COUNT following characters. */
  70.      int
  71.      invert_case_line (count, key)
  72.           int count, key;
  73.      {
  74.        register int start, end, i;
  75.      
  76.        start = rl_point;
  77.      
  78.        if (rl_point >= rl_end)
  79.          return (0);
  80.      
  81.        if (count < 0)
  82.          {
  83.            direction = -1;
  84.            count = -count;
  85.          }
  86.        else
  87.          direction = 1;
  88.      
  89.        /* Find the end of the range to modify. */
  90.        end = start + (count * direction);
  91.      
  92.        /* Force it to be within range. */
  93.        if (end > rl_end)
  94.          end = rl_end;
  95.        else if (end < 0)
  96.          end = 0;
  97.      
  98.        if (start == end)
  99.          return (0);
  100.      
  101.        if (start > end)
  102.          {
  103.            int temp = start;
  104.            start = end;
  105.            end = temp;
  106.          }
  107.      
  108.        /* Tell readline that we are modifying the line, so it will save
  109.           the undo information. */
  110.        rl_modifying (start, end);
  111.      
  112.        for (i = start; i != end; i++)
  113.          {
  114.            if (uppercase_p (rl_line_buffer[i]))
  115.              rl_line_buffer[i] = to_lower (rl_line_buffer[i]);
  116.            else if (lowercase_p (rl_line_buffer[i]))
  117.              rl_line_buffer[i] = to_upper (rl_line_buffer[i]);
  118.          }
  119.        /* Move point to on top of the last character changed. */
  120.        rl_point = (direction == 1) ? end - 1 : start;
  121.        return (0);
  122.      }
  123. File: readline.info,  Node: Custom Completers,  Prev: Readline Convenience Functions,  Up: Programming with GNU Readline
  124. Custom Completers
  125. =================
  126.    Typically, a program that reads commands from the user has a way of
  127. disambiguating commands and data.  If your program is one of these, then
  128. it can provide completion for commands, data, or both.  The following
  129. sections describe how your program and Readline cooperate to provide
  130. this service.
  131. * Menu:
  132. * How Completing Works::    The logic used to do completion.
  133. * Completion Functions::    Functions provided by Readline.
  134. * Completion Variables::    Variables which control completion.
  135. * A Short Completion Example::    An example of writing completer subroutines.
  136. File: readline.info,  Node: How Completing Works,  Next: Completion Functions,  Up: Custom Completers
  137. How Completing Works
  138. --------------------
  139.    In order to complete some text, the full list of possible completions
  140. must be available.  That is, it is not possible to accurately expand a
  141. partial word without knowing all of the possible words which make sense
  142. in that context.  The Readline library provides the user interface to
  143. completion, and two of the most common completion functions:  filename
  144. and username.  For completing other types of text, you must write your
  145. own completion function.  This section describes exactly what such
  146. functions must do, and provides an example.
  147.    There are three major functions used to perform completion:
  148.   1. The user-interface function `rl_complete ()'.  This function is
  149.      called with the same arguments as other Readline functions
  150.      intended for interactive use:  COUNT and INVOKING_KEY.  It
  151.      isolates the word to be completed and calls `completion_matches
  152.      ()' to generate a list of possible completions.  It then either
  153.      lists the possible completions, inserts the possible completions,
  154.      or actually performs the completion, depending on which behavior
  155.      is desired.
  156.   2. The internal function `completion_matches ()' uses your
  157.      "generator" function to generate the list of possible matches, and
  158.      then returns the array of these matches.  You should place the
  159.      address of your generator function in
  160.      `rl_completion_entry_function'.
  161.   3. The generator function is called repeatedly from
  162.      `completion_matches ()', returning a string each time.  The
  163.      arguments to the generator function are TEXT and STATE.  TEXT is
  164.      the partial word to be completed.  STATE is zero the first time
  165.      the function is called, allowing the generator to perform any
  166.      necessary initialization, and a positive non-zero integer for each
  167.      subsequent call.  When the generator function returns `(char
  168.      *)NULL' this signals `completion_matches ()' that there are no
  169.      more possibilities left.  Usually the generator function computes
  170.      the list of possible completions when STATE is zero, and returns
  171.      them one at a time on subsequent calls.  Each string the generator
  172.      function returns as a match must be allocated with `malloc()';
  173.      Readline frees the strings when it has finished with them.
  174.  - Function: int rl_complete (int ignore, int invoking_key)
  175.      Complete the word at or before point.  You have supplied the
  176.      function that does the initial simple matching selection algorithm
  177.      (see `completion_matches ()').  The default is to do filename
  178.      completion.
  179.  - Variable: Function * rl_completion_entry_function
  180.      This is a pointer to the generator function for `completion_matches
  181.      ()'.  If the value of `rl_completion_entry_function' is `(Function
  182.      *)NULL' then the default filename generator function,
  183.      `filename_entry_function ()', is used.
  184. File: readline.info,  Node: Completion Functions,  Next: Completion Variables,  Prev: How Completing Works,  Up: Custom Completers
  185. Completion Functions
  186. --------------------
  187.    Here is the complete list of callable completion functions present in
  188. Readline.
  189.  - Function: int rl_complete_internal (int what_to_do)
  190.      Complete the word at or before point.  WHAT_TO_DO says what to do
  191.      with the completion.  A value of `?' means list the possible
  192.      completions.  `TAB' means do standard completion.  `*' means
  193.      insert all of the possible completions.  `!' means to display all
  194.      of the possible completions, if there is more than one, as well as
  195.      performing partial completion.
  196.  - Function: int rl_complete (int ignore, int invoking_key)
  197.      Complete the word at or before point.  You have supplied the
  198.      function that does the initial simple matching selection algorithm
  199.      (see `completion_matches ()' and `rl_completion_entry_function').
  200.      The default is to do filename completion.  This calls
  201.      `rl_complete_internal ()' with an argument depending on
  202.      INVOKING_KEY.
  203.  - Function: int rl_possible_completions (int count, int invoking_key))
  204.      List the possible completions.  See description of `rl_complete
  205.      ()'.  This calls `rl_complete_internal ()' with an argument of `?'.
  206.  - Function: int rl_insert_completions (int count, int invoking_key))
  207.      Insert the list of possible completions into the line, deleting the
  208.      partially-completed word.  See description of `rl_complete ()'.
  209.      This calls `rl_complete_internal ()' with an argument of `*'.
  210.  - Function: char ** completion_matches (char *text, CPFunction
  211.           *entry_func)
  212.      Returns an array of `(char *)' which is a list of completions for
  213.      TEXT.  If there are no completions, returns `(char **)NULL'.  The
  214.      first entry in the returned array is the substitution for TEXT.
  215.      The remaining entries are the possible completions.  The array is
  216.      terminated with a `NULL' pointer.
  217.      ENTRY_FUNC is a function of two args, and returns a `(char *)'.
  218.      The first argument is TEXT.  The second is a state argument; it is
  219.      zero on the first call, and non-zero on subsequent calls.
  220.      eNTRY_FUNC returns a `NULL'  pointer to the caller when there are
  221.      no more matches.
  222.  - Function: char * filename_completion_function (char *text, int state)
  223.      A generator function for filename completion in the general case.
  224.      Note that completion in Bash is a little different because of all
  225.      the pathnames that must be followed when looking up completions
  226.      for a command.  The Bash source is a useful reference for writing
  227.      custom completion functions.
  228.  - Function: char * username_completion_function (char *text, int state)
  229.      A completion generator for usernames.  TEXT contains a partial
  230.      username preceded by a random character (usually `~').  As with all
  231.      completion generators, STATE is zero on the first call and non-zero
  232.      for subsequent calls.
  233. File: readline.info,  Node: Completion Variables,  Next: A Short Completion Example,  Prev: Completion Functions,  Up: Custom Completers
  234. Completion Variables
  235. --------------------
  236.  - Variable: Function * rl_completion_entry_function
  237.      A pointer to the generator function for `completion_matches ()'.
  238.      `NULL' means to use `filename_entry_function ()', the default
  239.      filename completer.
  240.  - Variable: CPPFunction * rl_attempted_completion_function
  241.      A pointer to an alternative function to create matches.  The
  242.      function is called with TEXT, START, and END.  START and END are
  243.      indices in `rl_line_buffer' saying what the boundaries of TEXT
  244.      are.  If this function exists and returns `NULL', or if this
  245.      variable is set to `NULL', then `rl_complete ()' will call the
  246.      value of `rl_completion_entry_function' to generate matches,
  247.      otherwise the array of strings returned will be used.
  248.  - Variable: int rl_completion_query_items
  249.      Up to this many items will be displayed in response to a
  250.      possible-completions call.  After that, we ask the user if she is
  251.      sure she wants to see them all.  The default value is 100.
  252.  - Variable: char * rl_basic_word_break_characters
  253.      The basic list of characters that signal a break between words for
  254.      the completer routine.  The default value of this variable is the
  255.      characters which break words for completion in Bash, i.e., `"
  256.      \t\n\"\\'`@$><=;|&{("'.
  257.  - Variable: char * rl_completer_word_break_characters
  258.      The list of characters that signal a break between words for
  259.      `rl_complete_internal ()'.  The default list is the value of
  260.      `rl_basic_word_break_characters'.
  261.  - Variable: char * rl_special_prefixes
  262.      The list of characters that are word break characters, but should
  263.      be left in TEXT when it is passed to the completion function.
  264.      Programs can use this to help determine what kind of completing to
  265.      do.  For instance, Bash sets this variable to "$@" so that it can
  266.      complete shell variables and hostnames.
  267.  - Variable: int rl_ignore_completion_duplicates
  268.      If non-zero, then disallow duplicates in the matches.  Default is
  269.      1.
  270.  - Variable: int rl_filename_completion_desired
  271.      Non-zero means that the results of the matches are to be treated as
  272.      filenames.  This is *always* zero on entry, and can only be changed
  273.      within a completion entry generator function.  If it is set to a
  274.      non-zero value, directory names have a slash appended and Readline
  275.      attempts to quote completed filenames if they contain any embedded
  276.      word break characters.
  277.  - Variable: int rl_filename_quoting_desired
  278.      Non-zero means that the results of the matches are to be quoted
  279.      using double quotes (or an application-specific quoting mechanism)
  280.      if the completed filename contains any characters in
  281.      `rl_completer_word_break_chars'.  This is *always* non-zero on
  282.      entry, and can only be changed within a completion entry generator
  283.      function.
  284.  - Variable: Function * rl_ignore_some_completions_function
  285.      This function, if defined, is called by the completer when real
  286.      filename completion is done, after all the matching names have
  287.      been generated.  It is passed a `NULL' terminated array of matches.
  288.      The first element (`matches[0]') is the maximal substring common
  289.      to all matches. This function can re-arrange the list of matches
  290.      as required, but each element deleted from the array must be freed.
  291.  - Variable: char * rl_completer_quote_characters
  292.      List of characters which can be used to quote a substring of the
  293.      line.  Completion occurs on the entire substring, and within the
  294.      substring `rl_completer_word_break_characters' are treated as any
  295.      other character, unless they also appear within this list.
  296. File: readline.info,  Node: A Short Completion Example,  Prev: Completion Variables,  Up: Custom Completers
  297. A Short Completion Example
  298. --------------------------
  299.    Here is a small application demonstrating the use of the GNU Readline
  300. library.  It is called `fileman', and the source code resides in
  301. `examples/fileman.c'.  This sample application provides completion of
  302. command names, line editing features, and access to the history list.
  303.      /* fileman.c -- A tiny application which demonstrates how to use the
  304.         GNU Readline library.  This application interactively allows users
  305.         to manipulate files and their modes. */
  306.      
  307.      #include <stdio.h>
  308.      #include <sys/types.h>
  309.      #include <sys/file.h>
  310.      #include <sys/stat.h>
  311.      #include <sys/errno.h>
  312.      
  313.      #include <readline/readline.h>
  314.      #include <readline/history.h>
  315.      
  316.      extern char *getwd ();
  317.      extern char *xmalloc ();
  318.      
  319.      /* The names of functions that actually do the manipulation. */
  320.      int com_list (), com_view (), com_rename (), com_stat (), com_pwd ();
  321.      int com_delete (), com_help (), com_cd (), com_quit ();
  322.      
  323.      /* A structure which contains information on the commands this program
  324.         can understand. */
  325.      
  326.      typedef struct {
  327.        char *name;            /* User printable name of the function. */
  328.        Function *func;        /* Function to call to do the job. */
  329.        char *doc;            /* Documentation for this function.  */
  330.      } COMMAND;
  331.      
  332.      COMMAND commands[] = {
  333.        { "cd", com_cd, "Change to directory DIR" },
  334.        { "delete", com_delete, "Delete FILE" },
  335.        { "help", com_help, "Display this text" },
  336.        { "?", com_help, "Synonym for `help'" },
  337.        { "list", com_list, "List files in DIR" },
  338.        { "ls", com_list, "Synonym for `list'" },
  339.        { "pwd", com_pwd, "Print the current working directory" },
  340.        { "quit", com_quit, "Quit using Fileman" },
  341.        { "rename", com_rename, "Rename FILE to NEWNAME" },
  342.        { "stat", com_stat, "Print out statistics on FILE" },
  343.        { "view", com_view, "View the contents of FILE" },
  344.        { (char *)NULL, (Function *)NULL, (char *)NULL }
  345.      };
  346.      
  347.      /* Forward declarations. */
  348.      char *stripwhite ();
  349.      COMMAND *find_command ();
  350.      
  351.      /* The name of this program, as taken from argv[0]. */
  352.      char *progname;
  353.      
  354.      /* When non-zero, this global means the user is done using this program. */
  355.      int done;
  356.      
  357.      char *
  358.      dupstr (s)
  359.           int s;
  360.      {
  361.        char *r;
  362.      
  363.        r = xmalloc (strlen (s) + 1);
  364.        strcpy (r, s);
  365.        return (r);
  366.      }
  367.      
  368.      main (argc, argv)
  369.           int argc;
  370.           char **argv;
  371.      {
  372.        char *line, *s;
  373.      
  374.        progname = argv[0];
  375.      
  376.        initialize_readline ();    /* Bind our completer. */
  377.      
  378.        /* Loop reading and executing lines until the user quits. */
  379.        for ( ; done == 0; )
  380.          {
  381.            line = readline ("FileMan: ");
  382.      
  383.            if (!line)
  384.              break;
  385.      
  386.            /* Remove leading and trailing whitespace from the line.
  387.               Then, if there is anything left, add it to the history list
  388.               and execute it. */
  389.            s = stripwhite (line);
  390.      
  391.            if (*s)
  392.              {
  393.                add_history (s);
  394.                execute_line (s);
  395.              }
  396.      
  397.            free (line);
  398.          }
  399.        exit (0);
  400.      }
  401.      
  402.      /* Execute a command line. */
  403.      int
  404.      execute_line (line)
  405.           char *line;
  406.      {
  407.        register int i;
  408.        COMMAND *command;
  409.        char *word;
  410.      
  411.        /* Isolate the command word. */
  412.        i = 0;
  413.        while (line[i] && whitespace (line[i]))
  414.          i++;
  415.        word = line + i;
  416.      
  417.        while (line[i] && !whitespace (line[i]))
  418.          i++;
  419.      
  420.        if (line[i])
  421.          line[i++] = '\0';
  422.      
  423.        command = find_command (word);
  424.      
  425.        if (!command)
  426.          {
  427.            fprintf (stderr, "%s: No such command for FileMan.\n", word);
  428.            return (-1);
  429.          }
  430.      
  431.        /* Get argument to command, if any. */
  432.        while (whitespace (line[i]))
  433.          i++;
  434.      
  435.        word = line + i;
  436.      
  437.        /* Call the function. */
  438.        return ((*(command->func)) (word));
  439.      }
  440.      
  441.      /* Look up NAME as the name of a command, and return a pointer to that
  442.         command.  Return a NULL pointer if NAME isn't a command name. */
  443.      COMMAND *
  444.      find_command (name)
  445.           char *name;
  446.      {
  447.        register int i;
  448.      
  449.        for (i = 0; commands[i].name; i++)
  450.          if (strcmp (name, commands[i].name) == 0)
  451.            return (&commands[i]);
  452.      
  453.        return ((COMMAND *)NULL);
  454.      }
  455.      
  456.      /* Strip whitespace from the start and end of STRING.  Return a pointer
  457.         into STRING. */
  458.      char *
  459.      stripwhite (string)
  460.           char *string;
  461.      {
  462.        register char *s, *t;
  463.      
  464.        for (s = string; whitespace (*s); s++)
  465.          ;
  466.      
  467.        if (*s == 0)
  468.          return (s);
  469.      
  470.        t = s + strlen (s) - 1;
  471.        while (t > s && whitespace (*t))
  472.          t--;
  473.        *++t = '\0';
  474.      
  475.        return s;
  476.      }
  477.      
  478.      /* **************************************************************** */
  479.      /*                                                                  */
  480.      /*                  Interface to Readline Completion                */
  481.      /*                                                                  */
  482.      /* **************************************************************** */
  483.      
  484.      char *command_generator ();
  485.      char **fileman_completion ();
  486.      
  487.      /* Tell the GNU Readline library how to complete.  We want to try to complete
  488.         on command names if this is the first word in the line, or on filenames
  489.         if not. */
  490.      initialize_readline ()
  491.      {
  492.        /* Allow conditional parsing of the ~/.inputrc file. */
  493.        rl_readline_name = "FileMan";
  494.      
  495.        /* Tell the completer that we want a crack first. */
  496.        rl_attempted_completion_function = (CPPFunction *)fileman_completion;
  497.      }
  498.      
  499.      /* Attempt to complete on the contents of TEXT.  START and END show the
  500.         region of TEXT that contains the word to complete.  We can use the
  501.         entire line in case we want to do some simple parsing.  Return the
  502.         array of matches, or NULL if there aren't any. */
  503.      char **
  504.      fileman_completion (text, start, end)
  505.           char *text;
  506.           int start, end;
  507.      {
  508.        char **matches;
  509.      
  510.        matches = (char **)NULL;
  511.      
  512.        /* If this word is at the start of the line, then it is a command
  513.           to complete.  Otherwise it is the name of a file in the current
  514.           directory. */
  515.        if (start == 0)
  516.          matches = completion_matches (text, command_generator);
  517.      
  518.        return (matches);
  519.      }
  520.      
  521.      /* Generator function for command completion.  STATE lets us know whether
  522.         to start from scratch; without any state (i.e. STATE == 0), then we
  523.         start at the top of the list. */
  524.      char *
  525.      command_generator (text, state)
  526.           char *text;
  527.           int state;
  528.      {
  529.        static int list_index, len;
  530.        char *name;
  531.      
  532.        /* If this is a new word to complete, initialize now.  This includes
  533.           saving the length of TEXT for efficiency, and initializing the index
  534.           variable to 0. */
  535.        if (!state)
  536.          {
  537.            list_index = 0;
  538.            len = strlen (text);
  539.          }
  540.      
  541.        /* Return the next name which partially matches from the command list. */
  542.        while (name = commands[list_index].name)
  543.          {
  544.            list_index++;
  545.      
  546.            if (strncmp (name, text, len) == 0)
  547.              return (dupstr(name));
  548.          }
  549.      
  550.        /* If no names matched, then return NULL. */
  551.        return ((char *)NULL);
  552.      }
  553.      
  554.      /* **************************************************************** */
  555.      /*                                                                  */
  556.      /*                       FileMan Commands                           */
  557.      /*                                                                  */
  558.      /* **************************************************************** */
  559.      
  560.      /* String to pass to system ().  This is for the LIST, VIEW and RENAME
  561.         commands. */
  562.      static char syscom[1024];
  563.      
  564.      /* List the file(s) named in arg. */
  565.      com_list (arg)
  566.           char *arg;
  567.      {
  568.        if (!arg)
  569.          arg = "";
  570.      
  571.        sprintf (syscom, "ls -FClg %s", arg);
  572.        return (system (syscom));
  573.      }
  574.      
  575.      com_view (arg)
  576.           char *arg;
  577.      {
  578.        if (!valid_argument ("view", arg))
  579.          return 1;
  580.      
  581.        sprintf (syscom, "more %s", arg);
  582.        return (system (syscom));
  583.      }
  584.      
  585.      com_rename (arg)
  586.           char *arg;
  587.      {
  588.        too_dangerous ("rename");
  589.        return (1);
  590.      }
  591.      
  592.      com_stat (arg)
  593.           char *arg;
  594.      {
  595.        struct stat finfo;
  596.      
  597.        if (!valid_argument ("stat", arg))
  598.          return (1);
  599.      
  600.        if (stat (arg, &finfo) == -1)
  601.          {
  602.            perror (arg);
  603.            return (1);
  604.          }
  605.      
  606.        printf ("Statistics for `%s':\n", arg);
  607.      
  608.        printf ("%s has %d link%s, and is %d byte%s in length.\n", arg,
  609.                finfo.st_nlink,
  610.                (finfo.st_nlink == 1) ? "" : "s",
  611.                finfo.st_size,
  612.                (finfo.st_size == 1) ? "" : "s");
  613.        printf ("Inode Last Change at: %s", ctime (&finfo.st_ctime));
  614.        printf ("      Last access at: %s", ctime (&finfo.st_atime));
  615.        printf ("    Last modified at: %s", ctime (&finfo.st_mtime));
  616.        return (0);
  617.      }
  618.      
  619.      com_delete (arg)
  620.           char *arg;
  621.      {
  622.        too_dangerous ("delete");
  623.        return (1);
  624.      }
  625.      
  626.      /* Print out help for ARG, or for all of the commands if ARG is
  627.         not present. */
  628.      com_help (arg)
  629.           char *arg;
  630.      {
  631.        register int i;
  632.        int printed = 0;
  633.      
  634.        for (i = 0; commands[i].name; i++)
  635.          {
  636.            if (!*arg || (strcmp (arg, commands[i].name) == 0))
  637.              {
  638.                printf ("%s\t\t%s.\n", commands[i].name, commands[i].doc);
  639.                printed++;
  640.              }
  641.          }
  642.      
  643.        if (!printed)
  644.          {
  645.            printf ("No commands match `%s'.  Possibilties are:\n", arg);
  646.      
  647.            for (i = 0; commands[i].name; i++)
  648.              {
  649.                /* Print in six columns. */
  650.                if (printed == 6)
  651.                  {
  652.                    printed = 0;
  653.                    printf ("\n");
  654.                  }
  655.      
  656.                printf ("%s\t", commands[i].name);
  657.                printed++;
  658.              }
  659.      
  660.            if (printed)
  661.              printf ("\n");
  662.          }
  663.        return (0);
  664.      }
  665.      
  666.      /* Change to the directory ARG. */
  667.      com_cd (arg)
  668.           char *arg;
  669.      {
  670.        if (chdir (arg) == -1)
  671.          {
  672.            perror (arg);
  673.            return 1;
  674.          }
  675.      
  676.        com_pwd ("");
  677.        return (0);
  678.      }
  679.      
  680.      /* Print out the current working directory. */
  681.      com_pwd (ignore)
  682.           char *ignore;
  683.      {
  684.        char dir[1024], *s;
  685.      
  686.        s = getwd (dir);
  687.        if (s == 0)
  688.          {
  689.            printf ("Error getting pwd: %s\n", dir);
  690.            return 1;
  691.          }
  692.      
  693.        printf ("Current directory is %s\n", dir);
  694.        return 0;
  695.      }
  696.      
  697.      /* The user wishes to quit using this program.  Just set DONE non-zero. */
  698.      com_quit (arg)
  699.           char *arg;
  700.      {
  701.        done = 1;
  702.        return (0);
  703.      }
  704.      
  705.      /* Function which tells you that you can't do this. */
  706.      too_dangerous (caller)
  707.           char *caller;
  708.      {
  709.        fprintf (stderr,
  710.                 "%s: Too dangerous for me to distribute.  Write it yourself.\n",
  711.                 caller);
  712.      }
  713.      
  714.      /* Return non-zero if ARG is a valid argument for CALLER, else print
  715.         an error message and return zero. */
  716.      int
  717.      valid_argument (caller, arg)
  718.           char *caller, *arg;
  719.      {
  720.        if (!arg || !*arg)
  721.          {
  722.            fprintf (stderr, "%s: Argument required.\n", caller);
  723.            return (0);
  724.          }
  725.      
  726.        return (1);
  727.      }
  728. File: readline.info,  Node: Concept Index,  Next: Function and Variable Index,  Prev: Programming with GNU Readline,  Up: Top
  729. Concept Index
  730. *************
  731. * Menu:
  732. * interaction, readline:                Readline Interaction.
  733. * Kill ring:                            Readline Killing Commands.
  734. * Killing text:                         Readline Killing Commands.
  735. * readline, function:                   Basic Behavior.
  736. * Yanking text:                         Readline Killing Commands.
  737. File: readline.info,  Node: Function and Variable Index,  Prev: Concept Index,  Up: Top
  738. Function and Variable Index
  739. ***************************
  740. * Menu:
  741. * $else:                                Conditional Init Constructs.
  742. * $endif:                               Conditional Init Constructs.
  743. * $if:                                  Conditional Init Constructs.
  744. * abort (C-g):                          Miscellaneous Commands.
  745. * accept-line (Newline, Return):        Commands For History.
  746. * alphabetic:                           Utility Functions.
  747. * backward-char (C-b):                  Commands For Moving.
  748. * backward-delete-char (Rubout):        Commands For Text.
  749. * backward-kill-line (C-x Rubout):      Commands For Killing.
  750. * backward-kill-word (M-DEL):           Commands For Killing.
  751. * backward-word (M-b):                  Commands For Moving.
  752. * beginning-of-history (M-<):           Commands For History.
  753. * beginning-of-line (C-a):              Commands For Moving.
  754. * bell-style:                           Readline Init Syntax.
  755. * call-last-kbd-macro (C-x e):          Keyboard Macros.
  756. * capitalize-word (M-c):                Commands For Text.
  757. * clear-screen (C-l):                   Commands For Moving.
  758. * comment-begin:                        Readline Init Syntax.
  759. * complete (TAB):                       Commands For Completion.
  760. * completion-query-items:               Readline Init Syntax.
  761. * completion_matches:                   Completion Functions.
  762. * convert-meta:                         Readline Init Syntax.
  763. * delete-char (C-d):                    Commands For Text.
  764. * delete-horizontal-space ():           Commands For Killing.
  765. * digit-argument (M-0, M-1, ... M-):    Numeric Arguments.
  766. * digit_p:                              Utility Functions.
  767. * digit_value:                          Utility Functions.
  768. * ding:                                 Utility Functions.
  769. * do-uppercase-version (M-a, M-b, ...): Miscellaneous Commands.
  770. * downcase-word (M-l):                  Commands For Text.
  771. * dump-functions ():                    Miscellaneous Commands.
  772. * editing-mode:                         Readline Init Syntax.
  773. * end-kbd-macro (C-x )):                Keyboard Macros.
  774. * end-of-history (M->):                 Commands For History.
  775. * end-of-line (C-e):                    Commands For Moving.
  776. * expand-tilde:                         Readline Init Syntax.
  777. * filename_completion_function:         Completion Functions.
  778. * forward-char (C-f):                   Commands For Moving.
  779. * forward-search-history (C-s):         Commands For History.
  780. * forward-word (M-f):                   Commands For Moving.
  781. * free_undo_list:                       Allowing Undoing.
  782. * history-search-backward ():           Commands For History.
  783. * history-search-forward ():            Commands For History.
  784. * horizontal-scroll-mode:               Readline Init Syntax.
  785. * insert-completions ():                Commands For Completion.
  786. * keymap:                               Readline Init Syntax.
  787. * kill-line (C-k):                      Commands For Killing.
  788. * kill-whole-line ():                   Commands For Killing.
  789. * kill-word (M-d):                      Commands For Killing.
  790. * lowercase_p:                          Utility Functions.
  791. * mark-modified-lines:                  Readline Init Syntax.
  792. * meta-flag:                            Readline Init Syntax.
  793. * next-history (C-n):                   Commands For History.
  794. * non-incremental-forward-search-history (M-n): Commands For History.
  795. * non-incremental-reverse-search-history (M-p): Commands For History.
  796. * numeric:                              Utility Functions.
  797. * output-meta:                          Readline Init Syntax.
  798. * possible-completions (M-?):           Commands For Completion.
  799. * prefix-meta (ESC):                    Miscellaneous Commands.
  800. * previous-history (C-p):               Commands For History.
  801. * quoted-insert (C-q, C-v):             Commands For Text.
  802. * re-read-init-file (C-x C-r):          Miscellaneous Commands.
  803. * readline:                             Basic Behavior.
  804. * redraw-current-line ():               Commands For Moving.
  805. * reverse-search-history (C-r):         Commands For History.
  806. * revert-line (M-r):                    Miscellaneous Commands.
  807. * rl_add_defun:                         Function Naming.
  808. * rl_add_undo:                          Allowing Undoing.
  809. * rl_attempted_completion_function:     Completion Variables.
  810. * rl_basic_word_break_characters:       Completion Variables.
  811. * rl_begin_undo_group:                  Allowing Undoing.
  812. * rl_bind_key:                          Binding Keys.
  813. * rl_bind_key_in_map:                   Binding Keys.
  814. * rl_clear_message:                     Redisplay.
  815. * rl_complete:                          How Completing Works.
  816. * rl_complete:                          Completion Functions.
  817. * rl_completer_quote_characters:        Completion Variables.
  818. * rl_completer_word_break_characters:   Completion Variables.
  819. * rl_complete_internal:                 Completion Functions.
  820. * rl_completion_entry_function:         Completion Variables.
  821. * rl_completion_entry_function:         How Completing Works.
  822. * rl_completion_query_items:            Completion Variables.
  823. * rl_copy_keymap:                       Keymaps.
  824. * rl_copy_text:                         Modifying Text.
  825. * rl_delete_text:                       Modifying Text.
  826. * rl_discard_keymap:                    Keymaps.
  827. * rl_done:                              Function Writing.
  828. * rl_do_undo:                           Allowing Undoing.
  829. * rl_end:                               Function Writing.
  830. * rl_end_undo_group:                    Allowing Undoing.
  831. * rl_filename_completion_desired:       Completion Variables.
  832. * rl_filename_quoting_desired:          Completion Variables.
  833. * rl_forced_update_display:             Redisplay.
  834. * rl_function_of_keyseq:                Associating Function Names and Bindings.
  835. * rl_generic_bind:                      Binding Keys.
  836. * rl_get_keymap:                        Keymaps.
  837. * rl_get_keymap_by_name:                Keymaps.
  838. * rl_ignore_completion_duplicates:      Completion Variables.
  839. * rl_ignore_some_completions_function:  Completion Variables.
  840. * rl_insert_completions:                Completion Functions.
  841. * rl_insert_text:                       Modifying Text.
  842. * rl_instream:                          Function Writing.
  843. * rl_invoking_keyseqs:                  Associating Function Names and Bindings.
  844. * rl_invoking_keyseqs_in_map:           Associating Function Names and Bindings.
  845. * rl_kill_text:                         Modifying Text.
  846. * rl_line_buffer:                       Function Writing.
  847. * rl_make_bare_keymap:                  Keymaps.
  848. * rl_make_keymap:                       Keymaps.
  849. * rl_mark:                              Function Writing.
  850. * rl_message:                           Redisplay.
  851. * rl_modifying:                         Allowing Undoing.
  852. * rl_named_function:                    Associating Function Names and Bindings.
  853. * rl_on_new_line:                       Redisplay.
  854. * rl_outstream:                         Function Writing.
  855. * rl_parse_and_bind:                    Binding Keys.
  856. * rl_pending_input:                     Function Writing.
  857. * rl_point:                             Function Writing.
  858. * rl_possible_completions:              Completion Functions.
  859. * rl_prompt:                            Function Writing.
  860. * rl_readline_name:                     Function Writing.
  861. * rl_redisplay:                         Redisplay.
  862. * rl_reset_line_state:                  Redisplay.
  863. * rl_reset_terminal:                    Utility Functions.
  864. * rl_set_keymap:                        Keymaps.
  865. * rl_special_prefixes:                  Completion Variables.
  866. * rl_startup_hook:                      Function Writing.
  867. * rl_terminal_name:                     Function Writing.
  868. * rl_unbind_key:                        Binding Keys.
  869. * rl_unbind_key_in_map:                 Binding Keys.
  870. * self-insert (a, b, A, 1, !, ...):     Commands For Text.
  871. * show-all-if-ambiguous:                Readline Init Syntax.
  872. * start-kbd-macro (C-x ():              Keyboard Macros.
  873. * tab-insert (M-TAB):                   Commands For Text.
  874. * tilde-expand (M-~):                   Miscellaneous Commands.
  875. * to_lower:                             Utility Functions.
  876. * to_upper:                             Utility Functions.
  877. * transpose-chars (C-t):                Commands For Text.
  878. * transpose-words (M-t):                Commands For Text.
  879. * undo (C-_, C-x C-u):                  Miscellaneous Commands.
  880. * universal-argument ():                Numeric Arguments.
  881. * unix-line-discard (C-u):              Commands For Killing.
  882. * unix-word-rubout (C-w):               Commands For Killing.
  883. * upcase-word (M-u):                    Commands For Text.
  884. * uppercase_p:                          Utility Functions.
  885. * username_completion_function:         Completion Functions.
  886. * yank (C-y):                           Commands For Killing.
  887. * yank-last-arg (M-., M-_):             Commands For History.
  888. * yank-nth-arg (M-C-y):                 Commands For History.
  889. * yank-pop (M-y):                       Commands For Killing.
  890.